﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    /// <summary>
    /// 系统模块
    /// </summary>
    public class ModularInfo
    {
        /// <summary>
        /// 模块ID
        /// </summary>
        public string ModularId
        {
            get;
            set;
        }
        /// <summary>
        /// 模块名称
        /// </summary>
        public string ModularName
        {
            get;
            set;
        }
        /// <summary>
        /// 模块URL
        /// </summary>
        public string ModularUrl
        {
            get;
            set;
        }

        public List<ModularInfo> GetModularAll()
        {
            DataAccessModular dam = new DataAccessModular();
            DataSet ds = dam.GetModular();
            List<ModularInfo> mulist = new List<ModularInfo>();
            ModularInfo muinfo;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                muinfo = new ModularInfo() { ModularId = dr[0].ToString(),
                                             ModularName = dr[1].ToString(),
                                             ModularUrl = dr[2].ToString() };
                mulist.Add(muinfo);                
            }
            return mulist;
        }
        /// <summary>
        /// 先清理绑定的角色模块
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int ClearBindModularToRole(string roleid)
        {
            DataAccessModular dam = new DataAccessModular();
            return dam.ClearBindModularToRole(roleid);
        }
        /// <summary>
        /// 绑定模块到角色
        /// </summary>
        /// <param name="mid"></param>
        /// <param name="logid"></param>
        /// <returns></returns>
        public int BindModularToRole(string mid, string roleid)
        {
            DataAccessModular dam = new DataAccessModular();
            return dam.BindModularToRole(mid, roleid);
        }
        /// <summary>
        /// 删除绑定
        /// </summary>
        /// <param name="mid"></param>
        /// <param name="logid"></param>
        /// <returns></returns>
        public int NotBindModular(string mid, string roleid)
        {
            DataAccessModular dam = new DataAccessModular();
            return dam.NotBindModular(mid, roleid);
        }

        /// <summary>
        /// 根据登录名称取模块
        /// </summary>
        /// <param name="logid"></param>
        /// <returns></returns>
        public List<ModularInfo> GetModularByLog(string logid)
        {
            DataAccessModular dam = new DataAccessModular();
            DataSet ds = dam.GetModular(logid);
            List<ModularInfo> mulist = new List<ModularInfo>();
            ModularInfo muinfo;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                muinfo = new ModularInfo()
                {
                    ModularId = dr[0].ToString(),
                    ModularName = dr[1].ToString(),
                    ModularUrl = dr[2].ToString()
                };
                mulist.Add(muinfo);
            }
            return mulist;

        }
        /// <summary>
        /// 根据角色获取模块
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public List<ModularInfo> GetModularByRole(string roleid)
        {
            DataAccessModular dam = new DataAccessModular();
            DataSet ds = dam.GetModularByRole(roleid);
            List<ModularInfo> mulist = new List<ModularInfo>();
            ModularInfo muinfo;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                muinfo = new ModularInfo()
                {
                    ModularId = dr[0].ToString(),
                    ModularName = dr[1].ToString(),
                    ModularUrl = dr[2].ToString()
                };
                mulist.Add(muinfo);
            }
            return mulist;
        }
    }
}
